package oj;

import java.util.HashSet;
import java.util.Set;

public class LC3 {
    public int lengthOfLongestSubstring(String s) {
        if(s.isEmpty()){
            return 0;
        }
        Set<Character> set=new HashSet<Character>();
        int i=0;
        int j=-1;
        int len=Integer.MIN_VALUE;
        char[] c=s.toCharArray();
        while(j+1<c.length){
            while(j+1<c.length && !set.contains(c[j+1])){
                set.add(c[j+1]);
                j++;
            }
            len=Math.max(len,j-i+1);
            set.remove(c[i]);
            i++;
        }
        return len;
    }
}